Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check request size for POST and POSTForm requests #24

Merged
merged 3 commits into from
Jul 4, 2024

Conversation

chaosrealm
Copy link
Contributor

@chaosrealm chaosrealm commented Jul 3, 2024

Check request size for POST and POSTForm requests. Fixes #20

Summary by CodeRabbit

  • New Features

    • Introduced a request size limit to enhance stability and prevent oversized requests.
    • Added error handling for requests that exceed the size limit.
  • Tests

    • Added a new test case to ensure proper error handling for oversized request bodies.

@chaosrealm chaosrealm requested review from EvanBoyle and jmoseley July 3, 2024 22:11
Copy link

coderabbitai bot commented Jul 3, 2024

Walkthrough

The update introduces a maxRequestSize property to the CortexApiClient class, encforcing request size limitations. New validation logic was added to check request body sizes, preventing over-sized requests. A new method, getFormDataSize, calculates FormData sizes. Unique test cases ensure that oversized requests properly throw errors.

Changes

File Description
api-client.ts Added maxRequestSize, request size validation in POSTForm, makeRequest, and a new getFormDataSize method.
content.test.ts Introduced a test case for handling oversized request bodies gracefully.

Assessment against linked issues

Objective Addressed Explanation
POST should check body size (#20)

Poem

In lines of code, a limit set,
To guard the bytes from undue fret.
With checks in place, and errors kind,
No more oversized requests to find.
A bunny's work, so neat and bright,
Keeping data snug and right.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d7089a8 and 92bdfd5.

Files selected for processing (1)
  • api-client.ts (2 hunks)
Additional context used
Biome
api-client.ts

[error] 44-44: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)

Additional comments not posted (3)
api-client.ts (3)

7-7: LGTM!

The maxRequestSize property is appropriately defined and initialized to 32 MB.


32-32: LGTM!

The request size check and error handling logic in the POSTForm method are correctly implemented.


65-65: LGTM!

The getFormDataSize method correctly calculates the size of FormData objects.

Copy link
Contributor

@jmoseley jmoseley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests?

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range and nitpick comments (1)
content.test.ts (1)

85-85: LGTM! Consider adding a comment to explain the purpose of the test.

The test case correctly checks if the system handles large request bodies by throwing an appropriate error.

To improve readability, consider adding a comment to explain the purpose of the test case.

+    // Test to ensure that requests with a body size exceeding the limit are rejected with an appropriate error
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 92bdfd5 and 8affacc.

Files selected for processing (2)
  • api-client.ts (3 hunks)
  • content.test.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • api-client.ts

@chaosrealm chaosrealm merged commit b7e06f7 into main Jul 4, 2024
3 checks passed
@@ -82,6 +82,12 @@ test(
expect(content.version).toBe(0);
expect(content.commands.length).toBe(1);

// check that prompt that is too large will fail gracefully without hitting the service
const hugePrompt = "p".repeat(32 * 1000 * 1000);
await expect(() =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think this should be a separate test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that, but prompt is a natural fit for testing this because it can be large but also easy to manipulate in test code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

POST should check body size
3 participants